package br.com.tcc.model;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.OneToMany;
import javax.persistence.Table;

@Entity
@Table(schema = "tcc", name = "posto")
public class Posto {
	
	public Posto() {
		combustiveis = null;
	}
	
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name="idPosto")
	private Long idPosto;
	
	@Column(name = "nm_posto", length = 100, nullable = false)
	private String nmPosto;
	
	@Column(name = "ds_endereco_posto", length = 100, nullable = false)
	private String dsEnderecoPosto;
	
	@Column(name = "nr_cnpj_posto", length = 100, nullable = false)
	private String nrCnpjPosto;
	
	@Column(name = "ds_bandeira", length = 100, nullable = false)
	private String dsBandeira;
	
	// 1 posto tem N combustiveis
	//@OneToMany(cascade = CascadeType.ALL, mappedBy = "posto", fetch = FetchType.LAZY)
	@OneToMany(cascade=CascadeType.ALL)
	  @JoinTable(schema = "tcc", name = "postocombustivel", joinColumns = {
	  @JoinColumn(name="postoId", unique = true) 
	  },
	  inverseJoinColumns = {
	  @JoinColumn(name="combustivelId")
	  }
	  )
	
	private Set<Combustivel> combustiveis;
	
	public void addCombustivel (Combustivel combustivel){
		
		if(combustivel == null)
			return;
		if(combustiveis == null){
			combustiveis = new HashSet<Combustivel>();
		}
		combustiveis.add(combustivel);
	}
	
	public void setCombustiveis(Set<Combustivel> combustiveis) {
		this.combustiveis = combustiveis;
	}
	public Set<Combustivel> getCombustiveis() {
		return combustiveis;
	}
	public Long getIdPosto() {
		return idPosto;
	}
	public void setIdPosto(Long idPosto) {
		this.idPosto = idPosto;
	}
	public String getNmPosto() {
		return nmPosto;
	}
	public void setNmPosto(String nmPosto) {
		this.nmPosto = nmPosto;
	}
	public String getDsEnderecoPosto() {
		return dsEnderecoPosto;
	}
	public void setDsEnderecoPosto(String dsEnderecoPosto) {
		this.dsEnderecoPosto = dsEnderecoPosto;
	}
	public String getNrCnpjPosto() {
		return nrCnpjPosto;
	}
	public void setNrCnpjPosto(String nrCnpjPosto) {
		this.nrCnpjPosto = nrCnpjPosto;
	}
	public String getDsBandeira() {
		return dsBandeira;
	}
	public void setDsBandeira(String dsBandeira) {
		this.dsBandeira = dsBandeira;
	}

	
}
